#include "m_utils.h"
#include <stdlib.h>

const static unsigned char c[] = "0123456789abcdef";

int m_to_hex(unsigned char *buf, unsigned int size, unsigned char *hex)
{
    for (unsigned int i = 0; i < size; i++) {
        *(hex + (2 * i)) = *(c + ((buf[i] & 0xF0) >> 4));
        *(hex + (2 * i + 1)) = *(c + (buf[i] & 0x0F));
    }
    hex[size * 2] = '\0';
    return 0;
}